package com.jinsp.webviewservice.webview;

import android.graphics.Bitmap;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

/**
 * Created by luoshuai on 12/30/21
 * <p>
 * 接收HTML返回信息
 */
public class DefaultWebChromeClient extends WebChromeClient {

    private final IWebViewCallback webViewCallback;

    public DefaultWebChromeClient(IWebViewCallback webViewCallback) {
        this.webViewCallback = webViewCallback;
    }

    @Override
    public void onReceivedIcon(WebView view, Bitmap icon) {
        if (webViewCallback != null) {
            webViewCallback.updateIcon(icon);
        }
    }

    @Override
    public void onReceivedTitle(WebView view, String title) {
        if (webViewCallback != null) {
            webViewCallback.updateTitle(title);
        }
    }

    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
        Log.d("CustomWebChromeClient", consoleMessage.message());
        return super.onConsoleMessage(consoleMessage);
    }
}
